<template>
  <div class="adminRole">
    <el-form
      ref="formRef"
      :inline="true"
      :model="form"
      class="search-form bg-bg_color w-[99/100] pl-8 pt-[12px]"
    >
      <el-form-item label="编码：" prop="code">
        <el-input
          v-model="form.code"
          placeholder="请输入编码"
          clearable
          class="!w-[200px]"
        />
      </el-form-item>
      <el-form-item label="内容：" prop="content">
        <el-input
          v-model="form.content"
          placeholder="请输入内容"
          clearable
          class="!w-[200px]"
        />
      </el-form-item>
      <el-form-item label="告警来源：" prop="recordtype">
        <el-input
          v-model="form.recordtype"
          placeholder="请输入告警来源"
          clearable
          class="!w-[200px]"
        />
      </el-form-item>
      <el-form-item label="车辆名称：" prop="agvid">
        <el-select v-model="form.agvid" clearable placeholder="请选择车辆名称" style="width:100%">
            <el-option
              v-for="item in agvSelect"
              :key="item.AgvId"
              :label="item.AgvName"
              :value="item.AgvId"
            />
          </el-select>
      </el-form-item>
      <el-form-item label="创建时间：" prop="dateRange">
        <el-date-picker
          v-model="form.dateRange"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          style="width:260px"
          @change="pickerChange"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" :icon="useRenderIcon(Search)" :loading="loading" @click="onSearch" >
          搜索
        </el-button>
        <el-button :icon="useRenderIcon(Refresh)" @click="resetForm(formRef)">
          重置
        </el-button>
      </el-form-item>
    </el-form>

    <PureTableBar
      title="告警管理"
      :columns="columns"
      @refresh="onSearch"
      >
      <template #buttons>
        <el-button type="primary" :icon="useRenderIcon(signOutBold)" @click="exportExcel()">
          导出
        </el-button>
      </template>
      <template v-slot="{ size, dynamicColumns }">
       <pure-table
          ref="tableRef"
          adaptive
          align-whole="center"
          row-key="Id"
          showOverflowTooltip
          table-layout="auto"
          :loading="loading"
          :size="size"
          :data="dataList"
          :columns="dynamicColumns"
          :pagination="pagination"
          :paginationSmall="size === 'small' ? true : false"
          :header-cell-style="{
            background: 'var(--el-fill-color-light)',
            color: 'var(--el-text-color-primary)'
          }"
          @page-size-change="handleSizeChange"
          @page-current-change="handleCurrentChange"
        >
          
        </pure-table>
      </template>
    </PureTableBar>
  </div>
</template>

<script lang='ts' setup>
import { PureTableBar } from "@/components/RePureTableBar";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import { useDept } from "./utils/hook";
import { ref } from 'vue'

// iconify-icons
import Search from "@iconify-icons/ep/search";
import Refresh from "@iconify-icons/ep/refresh";
import signOutBold from '@iconify-icons/ph/sign-out-bold';

const formRef = ref();

const pickerChange = () => {
  form.dateRange === null ? form.begin = "" : form.begin = form.dateRange[0]
  form.dateRange === null ? form.end = "" : form.end = form.dateRange[1]
}

const {
  columns,
  loading,
  dataList,
  exportExcel,
  form,
  onSearch,
  resetForm,
  pagination,
  handleSizeChange,
  handleCurrentChange,
  agvSelect
} = useDept();

</script>

<style lang="scss" scoped>
.search-form {
  :deep(.el-form-item) {
    margin-bottom: 12px;
  }
}
</style>